Walkthrough 10-6: Map an error to a custom error type

In this walkthrough, you map the Validation error to a custom error type for the application. You will:

·       Map a module error to a custom error type for an application.

·       Create an event handler for the custom error type.

Starting file

If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.

Map a validation module error to a custom error type

1.     Return to implementation.xml.

2.     Navigate to the properties view for the validator in getFlights.

3.     Select the Error Mapping tab.

4.     Click the Add new mapping button.

 

5.     Select the VALIDATION:INVALID_BOOLEAN error type.

6.     Leave the namespace of the custom error to map to set to APP.

7.     Set the identifier to INVALID_DESTINATION.

 

8.     Press Enter; you should see your new error mapping.

 

Change the existing validation error handler to catch the new custom type

9.     Navigate to the properties view for the getFlights validation On Error Continue error handler.

10.  Change the type from VALIDATION:INVALID_BOOLEAN to the new APP:INVALID_DESTINATION that should now appear in the type drop-down menu.

 

Test the application

11.  Save the file, run the project, and proceed through any errors in the workspace.

12.  In Advanced REST Client, change the code and make a request to http://localhost:8081/flights?code=FOO; you should still get a 400 response with the invalid destination error.

Move the American error handler into the American flow

13.  Collapse the getAllAirlineFlights and setCode flows.

14.  Move the AMERICAN-FLIGHTS-API error scope from getFlights into getAmericanFlights.

Move the error handler to the global error handler

Note: The following steps have instructions to make changes in the XML. If you prefer, you can copy and paste the error handler to move it between files and then delete the original.

15.  Right-click the validation On Error Continue error handler in getFlights and select Go to XML.

16.  Select and cut the APP:INVALID_DESTINATION on-error-continue.

17.  Delete the remaining, empty error-handler tag set.

18.  Return to global.xml.

19.  Right-click the globalError_Handler and select Go to XML.

20.  Place the cursor on a new line inside and at the start of the globalError_Handler error-handler.

21.  Paste the on-error-continue you cut to the clipboard.

 

Note: If you are prompted to regenerate ID values, click Yes.

22.  Switch back to the Message Flow view; you should see the APP:INVALID_DESTINATION handler.

 

23.  Return to implementation.xml and switch to the Message Flow view; you should no longer see an error handler in getFlights.

 

Test the application

24.  Save the files to redeploy the project.

25.  In Advanced REST Client, make another request to http://localhost:8081/flights?code=FOO; you should still get a 400 response with the invalid destination error.

26.  Change the code and make a request to http://localhost:8081/flights?code=PDX; you should still get only United flights to PDX.

 



Did you complete the walkthrough?

  Yes, I completed the walkthrough

  No, I did not complete the walkthrough

  I completed part of the walkthrough


Comments and/or feedback